#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<stdlib.h>

int main()
{
    pid_t id = fork();
    if(id==0)
    {
        //child
        int cnt=5;
        while(cnt)
        {
            printf("child is running,pid :%d,ppid:%d\n",getpid(),getppid());
            sleep(1);
            cnt--;
        }
        //printf("子进程准备退出，马上变僵尸进程\n");
        exit(1);
    }
    //printf("父进程休眠\n");
   // sleep(15);
   // printf("父进程开始回收了\n");
    //father
    int status=0;
    pid_t rid=waitpid(id,&status,0);
    if(rid>0)
    {
        printf("wait success,rid:%d,status:%d\n",rid,status);
    }
   // printf("父进程回收僵尸进程成功");
    //sleep(10);
    return 0;
}
